package cn.iocoder.yudao.module.wms.dal.mysql.inventory.stock;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.wms.controller.admin.inventory.stock.vo.InventoryStockPageReqVO;
import cn.iocoder.yudao.module.wms.controller.admin.inventory.stock.vo.InventoryStockReqVO;
import cn.iocoder.yudao.module.wms.dal.dataobject.inventory.stock.InventoryStockDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

/**
 * 存货现存量 Mapper
 *
 * @author 曾劲松
 */
@Mapper
public interface InventoryStockMapper extends BaseMapperX<InventoryStockDO> {

    default PageResult<InventoryStockDO> selectPage(InventoryStockPageReqVO reqVO, Collection<Long> classifyIds) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InventoryStockDO>()
                .likeIfPresent(InventoryStockDO::getCode, reqVO.getCode())
                .likeIfPresent(InventoryStockDO::getName, reqVO.getName())
                .likeIfPresent(InventoryStockDO::getSpecModel, reqVO.getSpecModel())
                .inIfPresent(InventoryStockDO::getClassifyId, classifyIds)
                .eqIfPresent(InventoryStockDO::getIsBatch, reqVO.getIsBatch())
                .likeIfPresent(InventoryStockDO::getBrand, reqVO.getBrand())
                .orderByDesc(InventoryStockDO::getCode));
    }

    default List<InventoryStockDO> selectList(String query) {
        return selectList(new LambdaQueryWrapperX<InventoryStockDO>()
                .like(InventoryStockDO::getCode,query)
                .or()
                .like(InventoryStockDO::getName,query)
                .or()
                .like(InventoryStockDO::getSpecModel,query)
                .orderByDesc(InventoryStockDO::getCode)
                .last("limit 100"));
    }

   Double findAvailableAmount(InventoryStockReqVO inventoryStockReqVO);

}